#include "cpu/exec/helper.h"

make_helper(jcc_rel8) {
    int8_t rel8 = instr_fetch(eip + 1, 1);
    uint8_t condition = ops_decoded.opcode & 0xF;

    bool taken = check_cc(condition);

    if (taken) {
        cpu.eip += rel8;
        print_asm("j%s 0x%x", get_cc_name(condition), cpu.eip);
    }
    else {
        print_asm("j%s 0x%x (not taken)", get_cc_name(condition), eip + 2 + rel8);
    }
    return 2;
}
  
make_helper(jcc_rel32) {
    int32_t rel32 = instr_fetch(eip + 2, 4);
    uint8_t condition = instr_fetch(eip + 1, 1) & 0xF;

    bool taken = check_cc(condition);

    if (taken) {
        cpu.eip += rel32;
        print_asm("j%s 0x%x", get_cc_name(condition), cpu.eip);
    }
    else {
        print_asm("j%s 0x%x (not taken)", get_cc_name(condition), eip + 6 + rel32);
    }
    return 6;
}